package com.zf.zffencheng.conf;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import springfox.documentation.builders.ParameterBuilder;
import springfox.documentation.builders.PathSelectors;
import springfox.documentation.builders.RequestHandlerSelectors;
import springfox.documentation.schema.ModelRef;
import springfox.documentation.service.ApiInfo;
import springfox.documentation.service.Contact;
import springfox.documentation.service.Parameter;
import springfox.documentation.spi.DocumentationType;
import springfox.documentation.spring.web.plugins.Docket;

import java.util.ArrayList;
import java.util.Collections;
import java.util.List;

/**
 * ClassName: SwaggerConfig <br/>
 * Description:  <br/>
 * date: 2021/5/7 10:07<br/>
 *
 * @author william <br/>
 */
@Configuration

public class SwaggerConfig {
    @Bean
    public Docket apiDocket() {
        return new Docket(DocumentationType.SWAGGER_2)
                .select()
                .apis(RequestHandlerSelectors.basePackage("com.zf.zffencheng.controller"))
                .paths(PathSelectors.any())
                .build()
                .apiInfo(getApiInfo()).globalOperationParameters(operationParameters());
    }

    private ApiInfo getApiInfo() {
        return new ApiInfo(
                "智佛,分成",
                "接口文档",
                "1.0.1",
                "",
                new Contact("NAME", "URL", "EMAIL"),
                "LICENSE",
                "LICENSE URL",
                Collections.emptyList()
        );
    }

    /**
     * 头部
     * @return
     */
    private List<Parameter> operationParameters(){
        List<Parameter> parameters = new ArrayList<>();
        ParameterBuilder paramHeader = new ParameterBuilder();
        paramHeader.name("Authorization").description("令牌")
                .modelRef(new ModelRef("string"))
                .parameterType("header").required(false)
                .build();
        parameters.add(paramHeader.build());
        return parameters;
    }
}
